package com.semicolon_dtn_student;

import java.util.ArrayList;
import java.util.Calendar;

import android.app.AlarmManager;
import android.content.Context;

public class ConstantVal {
	public static final int RESULT_FAIL = -1;
	public static final int RESULT_DEFAULT = 0;
	public static final int RESULT_SEMI_SUCCESS = 1;
	public static final int RESULT_SUCCESS = 2;
	
	public static ArrayList<ScheduleInfo> sched_list = new ArrayList<ScheduleInfo>();
	public static ScheduleListAdapter list_adapter;
	
	public static int day_percent = 0;
    
	public static int calculateDayPercent(int year, int month, int day)
	{	
		int percent = 0;
		int total = 0;
		int full = 0;
		for(int i = 0 ; i < sched_list.size() ; i++)
		{
			int tYear = sched_list.get(i).getYear();
			int tMonth = sched_list.get(i).getMonth();
			int tDay = sched_list.get(i).getDay();

			if(year == tYear && tMonth == month && day == tDay)
			{
				int result = sched_list.get(i).getResult();
				if(result == RESULT_FAIL)
				{
					result += 1;
				}
				total += result;
				full += RESULT_SUCCESS;
			}
		}
		percent = (int)( ( (double)total / (double)full ) * 100 );
		return percent;
	}
	
	// sort schedule array list by time
	public static void sortArrayListByTime()
	{
		int year, month, day, hour1, minute1, hour2, minute2;
		Calendar c1 = Calendar.getInstance();
		Calendar c2 = Calendar.getInstance();
		
		for(int i = 0 ; i < sched_list.size() - 1 ; i++)
		{
			for(int j = 0 ; j < sched_list.size() - 1 ; j++)
			{
				year = sched_list.get(j).getYear();
				month = sched_list.get(j).getMonth();
				day = sched_list.get(j).getDay();
				hour1 = sched_list.get(j).getHour1();
				hour2 = sched_list.get(j).getHour2();
				minute1 = sched_list.get(j).getMinute1();
				minute2 = sched_list.get(j).getMinute2();
				
				c1.set(year, month, day, hour1, minute1, 0);
				
				int j_next = j+1;
				year = sched_list.get(j_next).getYear();
				month = sched_list.get(j_next).getMonth();
				day = sched_list.get(j_next).getDay();
				hour1 = sched_list.get(j_next).getHour1();
				hour2 = sched_list.get(j_next).getHour2();
				minute1 = sched_list.get(j_next).getMinute1();
				minute2 = sched_list.get(j_next).getMinute2();
				
				c2.set(year, month, day, hour1, minute1, 0);
				
				// change
				if(c1.after(c2))
				{
					ScheduleInfo sched = sched_list.get(j);
					sched_list.remove(j);
					sched_list.add(j+1, sched);
				}
				
			}
			
		}
		
		
	}
}
